<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button>删除</button>
    <ul>
      <li>111</li>
      <li>222</li>
      <li>333</li>
    </ul>
    <script>
      //需求  : 点击删除按钮 如果有li就去删除
      //1. 获取元素
      var btn = document.querySelector('button');
      btn.onclick = function () {
        //2.删除元素  node .removeChild(child)
        var ul = document.querySelector('ul');
        //
        if (ul.children.length !== 0) {
          ul.removeChild(ul.children[0]); // children子元素       removeChild删除儿子的节点
        }
      };
    </script>
  </body>
</html>
